home *** CD-ROM | disk | FTP | other *** search
/ Almathera Ten Pack 3: CDPD 3 / Almathera Ten on Ten - Disc 3: CDPD3.iso / scope / 001-025 / scopedisk2 / vac1.5 / vac.asm < prev    next >
Assembly Source File  |  1995-03-18  |  10KB  |  459 lines

  1. *******************************************************************************
  2. *                                                                             *
  3. * VacBench.asm  Version 1.5 By Randy Jouett  02/8/88 (MetaCompost).           *
  4. * This program is released into the pubic/public domain :-)                   *
  5. * If you notice any bugs, please e-mail me at one of the following addresses: *
  6. *                                                                             *
  7. *               {ihnp4,cbosgd}!killer!usl!usl-pc!jpdres11                     *
  8. *                      ut-sally!usl!usl-pc!jpdres11                           *
  9. *                       jpdres11%usl-pc@usl.CSNET                             *
  10. *                                                                             *
  11. *******************************************************************************
  12.  
  13.     TTL    VacBench.asm
  14.  
  15.     include    "macros.i"
  16.     include    "intuition.i"
  17.     include    "view.i"
  18.     include    "gfx.i"
  19.     include    "ibase.i"
  20.     include    "rastport.i"
  21.     include    "screens.i"
  22.     include "memory.i"
  23.  
  24.     XLVO    OpenLibrary
  25.     XLVO    CloseLibrary
  26.     XLVO    OpenWindow
  27.     XLVO    CloseWindow
  28.     XLVO    ActivateWindow
  29.     XLVO    ViewPortAddress
  30.     XLVO    ReadPixel
  31.     XLVO    WritePixel
  32.     XLVO    BltBitMapRastPort
  33.     XLVO    BltBitMap
  34.     XLVO    SetAPen
  35.     XLVO    GetMsg
  36.     XLVO    ReplyMsg
  37.     XLVO    SetPointer
  38.     XLVO    ClearPointer
  39.     XLVO    SetRGB4
  40.     XLVO    AllocRaster
  41.     XLVO    FreeRaster
  42.     XLVO    AllocMem
  43.     XLVO    FreeMem
  44.     XLVO    InitBitMap
  45.     XLVO    LoadRGB4
  46.  
  47. VACWIDTH    equ    16
  48. VACHEIGHT    equ    46
  49.  
  50. * Open IntuitionBase and GfxBase
  51. main:
  52.     moveq    #0,d0            ;Library version.
  53.     lea.l    GfxName,a1        ;Put address of graphics.library in a1.
  54.     SYS    OpenLibrary,4        ;Open graphics.library.
  55.     move.l    d0,GBase        ;Save library ptr.
  56.  
  57.     moveq    #0,d0            ;Now do same for Intuition library
  58.     lea.l    IntuiName,a1
  59.     SYS    OpenLibrary
  60.     move.l    d0,IBase
  61.  
  62.     move.l    IBase,a2
  63.     move.l    ib_ActiveScreen(a2),a2        ;Get ActiveScreen.
  64.     lea.l    sc_ViewPort(a2),a4
  65.     move.l    a4,svp                ;The ViewPort.
  66.     lea.l    sc_RastPort(a2),a2        ;The RastPort.
  67.     move.l    vp_ColorMap(a4),a4        ;The ColorMap.
  68.  
  69.     move.l    cm_ColorTable(a4),a0        ;The ColorTable.
  70.     lea.l    ctable,a1
  71.     moveq    #31,d0
  72. 1$:
  73.     move.w    (a0)+,(a1)+
  74.     dbf    d0,1$
  75.  
  76.     move.l    #32,count
  77.     move.l    rp_BitMap(a2),a2        ;The Bitmap.
  78.     move.l    a2,bm1                ;Save BitMap ptr.
  79.     moveq    #0,d0
  80.     move.b    bm_Depth(a2),d0            ;Get Depth.
  81.     move.l    d0,depth
  82.     move.w    bm_BytesPerRow(a2),d0        ;Calculate width.
  83.     lsl.w    #3,d0
  84.     move.l    d0,width
  85.     moveq    #0,d0
  86.     move.w    bm_Rows(a2),d0
  87.     move.l    d0,height            ;Save height.
  88.     
  89.     move.l    #bm_SIZEOF,d0
  90.     move.l    #MEMF_CHIP!MEMF_CLEAR,d1    ;Chip mem. Clear it out.
  91.     SYS    AllocMem            ;Allocate the mem.
  92.     move.l    d0,bm2                ;Save prt for new BitMap. 
  93.     beq    cleanup
  94.  
  95.     move.l    bm2,a0                ;Init the Bitmap
  96.     move.l    depth,d0
  97.     move.l    width,d1
  98.     move.l    height,d2
  99.     SYS    InitBitMap,GBase
  100.  
  101.     move.l    depth,d3
  102.     subq.w    #1,d3
  103.     move.l    bm2,a2
  104.     lea.l    bm_Planes(a2),a3
  105. alloc:
  106.     move.l    width,d0
  107.     move.l    height,d1
  108.     SYS    AllocRaster
  109.     move.l    d0,(a3)+
  110.     dbf    d3,alloc
  111.  
  112.     move.l    bm1,a0                ;Copy the RastPorts BitMap to
  113.     moveq    #0,d0                ;our new BitMap.
  114.     moveq    #0,d1
  115.     move.l    bm2,a1
  116.     moveq    #0,d2
  117.     moveq    #0,d3
  118.     move.l    width,d4
  119.     move.l    height,d5
  120.     move.l    #$0c0,d6
  121.     move.l    #$fff,d7
  122.     move.l    #0,a2
  123.     SYS    BltBitMap
  124.  
  125.     lea.l    newwin,a2            ;Save Width & height in the
  126.     move.l    width,d0            ;proper fields.
  127.     move.w    d0,nw_Width(a2)
  128.     move.l    height,d0
  129.     move.w    d0,nw_Height(a2)
  130.     move.l    a2,a0
  131.     SYS    OpenWindow,IBase        ;Open the Window.
  132.     move.l    d0,vacwin            ;Save prt to mywin
  133.  
  134.     move.l    vacwin,a0            ;Get the window's ViewPort.
  135.     SYS    ViewPortAddress
  136.     move.l    d0,vp                ;Save vp.
  137.  
  138.     move.l    vacwin,a5            ;Grab window's RastPort.
  139.     move.l    wd_RPort(a5),d0
  140.     move.l    d0,rp                ;Save rp.
  141.  
  142.     move.l    bm2,a0                ;Blit the new BitMap to our
  143.     moveq    #0,d0                ;window's RastPort.
  144.     moveq    #0,d1
  145.     move.l    rp,a1
  146.     moveq    #0,d2
  147.     moveq    #0,d3
  148.     move.l    width,d4
  149.     move.l    height,d5
  150.     move.l    #$0c0,d6
  151.     SYS    BltBitMapRastPort,GBase
  152.  
  153. * SetPointer to Vaccume Cleaner
  154.  
  155.     lea.l    vaccolors,a2            ;get colors
  156.     moveq    #0,d5    
  157.     moveq    #0,d6
  158. setprt:                        ;Set register colors.
  159.     cmp.w    #3,d5
  160.     beq    1$
  161.     move.w    (a2)+,d6
  162.     move.l    d6,d0
  163.     and.w    #$f00,d6
  164.     lsr.w    #8,d6
  165.     move.l    d6,red
  166.     move.l    d0,d6
  167.     and.w    #$0f0,d6
  168.     lsr.w    #4,d6
  169.     move.l    d6,green
  170.     move.l    d0,d6
  171.     and.w    #$00f,d6
  172.     move.l    d6,blue
  173.     move.l    vp,a0                ;Put vp in a0.
  174.     move.l    d5,d0
  175.     add.w    #17,d0                ;Calculate proper register.
  176.     move.l    red,d1                ;Move colors into registers.
  177.     move.l    green,d2
  178.     move.l    blue,d3
  179.     SYS    SetRGB4                ;Set the colors.
  180.     add.w    #1,d5                ;Bump counter.
  181.     jmp    setprt                ;Do it again.
  182. 1$:
  183.     moveq    #0,d0                ;SetPointer to vaccume 
  184.     move.l    vacwin,a0            ;cleaner.
  185.     lea.l    vacsprite,a1
  186.     move.l    #VACHEIGHT,d0
  187.     move.l    #VACWIDTH,d1
  188.     moveq    #1,d2
  189.     moveq    #1,d3
  190.     SYS    SetPointer,IBase
  191.  
  192.     move.l    vacwin,a0
  193.     SYS    ActivateWindow            ;Active the Window.
  194.  
  195. ****** Vac: The heart of the code ******
  196.  
  197.     move.l    IBase,a5
  198.     move.l    ib_ActiveScreen(a5),a5
  199.     moveq    #0,d0
  200.     move.b    sc_DetailPen(a5),d0
  201.     move.l    d0,bgpen
  202.     move.b    sc_BlockPen(a5),d0
  203.     move.l    d0,fgpen
  204.     move.l    vacwin,a3
  205. vac:
  206.     move.l    wd_UserPort(a3),a0        ;Grab the UserPort and get
  207.     SYS    GetMsg,4            ;a message.
  208.     tst.l    d0
  209.     beq    1$
  210.     move.l    d0,a1
  211.     SYS    ReplyMsg            ;Reply to the message and get
  212.     bra    cleanup                ;out.
  213. 1$:
  214.     moveq    #0,d0
  215.     move.w    sc_MouseX(a5),d0        
  216.     move.l    d0,mx                ;Save MouseX in mx
  217.     move.w    sc_MouseY(a5),d0
  218.     move.l    d0,my                ;Save MouseY in my
  219.     moveq    #10,d5                ;Size of Matrix
  220.     moveq    #10,d6                ;Offset for x
  221.     moveq    #10,d7                ;Offset for y
  222. 2$:
  223.     move.l    rp,a1                ;Put rp in a1
  224.     move.l    mx,d2
  225.     move.l    my,d3
  226.     sub.l    d6,d2
  227.     move.l    d2,d0                ;Put x in d0 for ReadPixel
  228.     sub.l    d7,d3
  229.     move.l    d3,d1                ;put y in d1 for ReadPixel.
  230.     SYS    ReadPixel,GBase            ;ReadPixel at location.
  231.     cmp.l    fgpen,d0            ;is it the same color a fgpen?
  232.     bne    3$                ;Nope. Go get another pixel.
  233.     move.l    rp,a1                ;Must be equal to fgpen.
  234.     move.l    bgpen,d0            ;Put bgpen in d0.
  235.     SYS    SetAPen                ;Set pen to background color.
  236.  
  237.     move.l    rp,a1
  238.     move.l    d2,d0
  239.     move.l    d3,d1
  240.     SYS    WritePixel            ;Change Pixel to background.
  241.  
  242.     move.l    rp,a1                
  243.     move.l    fgpen,d0
  244.     SYS    SetAPen                ;Set pen back to fgpen.
  245.  
  246.     move.l    rp,a1                ;Write the pixel @ x+1 y+1
  247.     addq    #1,d2
  248.     move.l    d2,d0
  249.     addq    #1,d3
  250.     move.l    d3,d1
  251.     SYS    WritePixel
  252. 3$:    
  253.     subq    #1,d6
  254.     tst.l    d6
  255.     beq    4$
  256.     bra    2$
  257. 4$:
  258.     moveq    #10,d6
  259.     subq    #1,d7
  260.     subq    #1,d5
  261.     beq    clearem                ;Hit Zero. Start over
  262.     bra    2$                ;Else, continue.
  263.  
  264. clearem:
  265.     move.l    rp,a1                ;Clear out pixels close to
  266.     move.l    bgpen,d0            ;sprite.
  267.     SYS    SetAPen
  268.  
  269.     moveq    #3,d4
  270.     lea.l    mxoffsets,a0
  271.     lea.l    myoffsets,a2
  272. 1$:
  273.     move.l    rp,a1
  274.     move.l    mx,d2
  275.     sub.w    (a0)+,d2
  276.     move.l    d2,d0
  277.     move.l    my,d3
  278.     sub.w    (a2)+,d3
  279.     move.l    d3,d1
  280.     SYS    WritePixel
  281.     dbne    d4,1$
  282.     bra    vac
  283.  
  284. ****** Clean up everything and exit program ******
  285.  
  286. cleanup:
  287.     move.l    svp,a0
  288.     lea.l    ctable,a1
  289.     move.l    count,d0
  290.     SYS    LoadRGB4,GBase
  291.  
  292.     moveq    #0,d0
  293.     move.l    depth,d4
  294.     subq.w    #1,d4
  295.     move.l    bm2,a3
  296.     lea.l    bm_Planes(a3),a3
  297. free:
  298.     move.l    (a3)+,a0
  299.     move.l    width,d0
  300.     move.l    height,d1
  301.     SYS    FreeRaster,GBase
  302.     dbf    d4,free
  303.  
  304.     move.l    bm2,a1
  305.     move.l    #bm_SIZEOF,d0
  306.     SYS    FreeMem,4
  307.  
  308.     move.l    vacwin,a0
  309.     SYS    ClearPointer,IBase        ;Clear out the Vac pointer.
  310.  
  311.     move.l    vacwin,a0
  312.     SYS    CloseWindow            ;Close the Window.
  313.  
  314.     move.l    IBase,a1            ;Put gfxbase in a1
  315.     SYS    CloseLibrary,4            ;Close graphics.library
  316.  
  317.     move.l    GBase,a1            ;Put gfxbase in a1
  318.     SYS    CloseLibrary            ;Close graphics.library
  319.     rts                    ;Exit program.
  320.  
  321. **************************************************************************
  322. *                            VacBench Data                               *
  323. **************************************************************************
  324.  
  325.     section    VacBenchdata,data
  326.  
  327. ****** Libraries ******
  328. IntuiName:
  329.     dc.b    'intuition.library',0
  330.     ds    0
  331.  
  332. GfxName:
  333.     dc.b    'graphics.library',0
  334.     ds    0
  335.  
  336. ****** Library Pointers ******
  337.     XDEF    GBase
  338. GBase:
  339.     ds.l    1
  340.     XDEF    IBase
  341. IBase:
  342.     ds.l    1
  343.  
  344. ****** NewWindow *****
  345. newwin:
  346.     dc.w    0,0                ;Left edge, top edge.
  347.     dc.w    0,0                ;Width, height.
  348.     dc.b    0,1                ;Detail and block pen.
  349.     dc.l    MOUSEBUTTONS              ;IDCMP flags.
  350.     dc.l    BORDERLESS!SIMPLE_REFRESH     ;Window flags.
  351.     dc.l    0                ;Prt to first gadget.
  352.     dc.l    0                ;Image (check mark).
  353.     dc.l    0                ;Window title ptr.
  354.     dc.l    0                ;Screen ptr.
  355.     dc.l    0                ;BitMap ptr.
  356.     dc.w    0,0                ;MinWidth, MinHeight.
  357.     dc.w    640,200                ;MaxWidth, MaxHeight.
  358.     dc.w    WBENCHSCREEN            ;Screen type.
  359.  
  360. ****** Window Stuff ******
  361. vacwin:
  362.     ds.l    1
  363. svp:
  364.     ds.l    1
  365. ctable:
  366.     ds.w    32
  367. count:
  368.     ds.l    1
  369. vp:
  370.     ds.l    1
  371. rp:
  372.     ds.l    1
  373. bm1:
  374.     ds.l    1
  375. bm2:
  376.     ds.l    1
  377. depth:
  378.     ds.l    1
  379. width:
  380.     ds.l    1
  381. height:
  382.     ds.l    1
  383. mx:
  384.     ds.l    1
  385. my:
  386.     ds.l    1
  387. fgpen:
  388.     ds.l    1
  389. bgpen:
  390.     ds.l    1
  391. red:
  392.     ds.l    1
  393. green:
  394.     ds.l    1
  395. blue:
  396.     ds.l    1
  397.  
  398. ****** Sprite Data ******
  399. vacsprite:
  400.     dc.w    $0000,$0000
  401.     dc.w    $0000,$7000
  402.     dc.w    $0000,$f800
  403.     dc.w    $0000,$f800
  404.     dc.w    $0c00,$fc00
  405.     dc.w    $1e00,$7e00
  406.     dc.w    $1f00,$1c00
  407.     dc.w    $0f80,$0800
  408.     dc.w    $07c0,$0000
  409.     dc.w    $03e0,$0000
  410.     dc.w    $01e0,$0000
  411.     dc.w    $01e0,$0000
  412.     dc.w    $01e0,$0000
  413.     dc.w    $01e0,$0000
  414.     dc.w    $01e0,$0000
  415.     dc.w    $01e0,$0000
  416.     dc.w    $01e0,$0000
  417.     dc.w    $01e0,$0000
  418.     dc.w    $01e0,$0000
  419.     dc.w    $01e0,$0210
  420.     dc.w    $03f0,$0618
  421.     dc.w    $07f8,$0e1c
  422.     dc.w    $0ffc,$1e1e
  423.     dc.w    $1ffe,$3e1f
  424.     dc.w    $1ffe,$3e1f
  425.     dc.w    $1ffe,$3f3f
  426.     dc.w    $1ffe,$3fff
  427.     dc.w    $0ffc,$3fff
  428.     dc.w    $17fa,$3fff
  429.     dc.w    $1bf6,$3fff
  430.     dc.w    $1c0e,$3fff
  431.     dc.w    $1dee,$3fff
  432.     dc.w    $1dee,$3fff    
  433.     dc.w    $1dee,$3fff
  434.     dc.w    $1dee,$3fff
  435.     dc.w    $1dee,$3fff
  436.     dc.w    $1dee,$3fff
  437.     dc.w    $1dee,$3fff
  438.     dc.w    $1dee,$3fff
  439.     dc.w    $1dee,$3fff
  440.     dc.w    $1dee,$3fff
  441.     dc.w    $1dee,$3fff
  442.     dc.w    $1dee,$3fff
  443.     dc.w    $0dee,$1fff
  444.     dc.w    $05ec,$0ffe
  445.     dc.w    $01e8,$07fc
  446.     dc.w    $0000,$03f8
  447.     dc.w    $0000,$0000
  448.  
  449. vaccolors:
  450.     dc.w    $567,$000,$e30
  451.     ds    0
  452.  
  453. mxoffsets:
  454.     dc.w    1,1,0,0
  455.  
  456. myoffsets:
  457.     dc.w    0,1,1,0
  458.     END
  459.